Repository navigation
Fix #15193 Wrong type for hex literals that do not fit in 32-bit long - #9026
wjakobsson wants to merge 3 commits into
Conversation
fd8f65b to
e9f7fde
Compare
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no problems in the change. Switching from value >> 2 to value >> 1 makes the "fits in unsigned int/long" check exact. For a biguint, value >> 1 <= INT_MAX is the same as value <= UINT_MAX. On unix32, unix64 and win64 every hex and binary literal I tried now gets the type the C standard gives it. The U and L suffixes work too.
One case is still wrong, and the PR does not cause it. MathLib::isDec() counts octal literals as decimal. So on unix32 037777777777 (= 0xFFFFFFFF) gets the type signed long long instead of unsigned int, in both base and PR. The bug is in the same !MathLib::isDec(tokStr) condition the PR edits, so it could be fixed here or in a separate ticket.
Testing
- Built
cppcheckandtestrunnerinpr/, andcppcheckinbase/. Both built cleanly. ./testrunner TestSymbolDatabase TestValueFlow TestType TestOther TestCondition: 863 tests, 0 failed.- Compared the
valueTypeof literals in--dumpoutput between base and PR on unix32, unix64 and win64, using:void f(void) { (void)0xFFFFFFFF; (void)0x1FFFFFFFF; (void)0x100000000; (void)0xFFFFFFFFU; (void)0x100000000U; (void)037777777777; (void)077777777777; (void)0x8000000000000000; (void)0xFFFFFFFFFFFFFFFFL; (void)0x100000000L; (void)0x80000000L; (void)0x8000000000000000L; }
- Base gave wrong types, for example
0x100000000→unsigned intand0x100000000L→unsigned longon unix32. - The PR gives the right types:
signed long longon unix32/win64 andsigned longon unix64.0x100000000U→unsigned long long/unsigned long.0xFFFFFFFFstaysunsigned int, and0x80000000Lstaysunsigned longon 32-bit long platforms. - Binary literals are also right, for example
0b1…1(32 ones) →unsigned int.
- Base gave wrong types, for example
- Older bug found again, the same in base and PR: octal
037777777777→signed long longon unix32. It should beunsigned int, becauseMathLib::isDectreats octal as decimal. - Older bug found again, the same in base and PR: an out-of-range literal
0x10000000000000000givesinternalErrorfromMathLib::toBigUNumber.
Automated review of e9f7fde by Claude. The pull request was built and tested locally.
|
Test results for commit e9f7fde (tools/test-my-pr.py, main compared to this PR): Test: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-9026/ Posted automatically by the cppcheck PR test runner. +N: warnings only with this PR, -N: warnings only with main. The AI review is written by Claude and can be wrong. |
e9f7fde to
4ca1d1b
Compare
4ca1d1b to
f23df7d
Compare
|
Test results for commit f23df7d (tools/test-my-pr.py, main compared to this PR): Test: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-9026/ Posted automatically by the cppcheck PR test runner. +N: warnings only with this PR, -N: warnings only with main. The AI review is written by Claude and can be wrong. |
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no new problems. The latest commit fixes the octal issue raised in C2. isDecimal = isDec && !isOct now sends octal literals down the same unsigned path as hex and binary literals. With the >> 1 checks, literals that fit in unsigned int or unsigned long get the type the C standard gives them on unix32, unix64 and win64. The new unit tests cover hex, octal and the unsigned/long suffixes.
Comments
| # | Comment | By | Where | Status |
|---|---|---|---|---|
| 1 | Octal literals treated as decimal by MathLib::isDec, so they never get unsigned types | AI review | lib/symboldatabase.cpp:8013 |
✅ Fixed |
Testing
-
Built
cppcheckandtestrunnerinpr/. The build finished with no errors. -
./testrunner TestSymbolDatabase: 430 tests, 0 failed. -
TestValueFlow,TestType,TestOther,TestCondition,Test64BitPortabilityandTestIO: 0 failed. -
Checked the
valueTypein the--dumpoutput on unix32, unix64 and win64 for these literals:037777777777, with no suffix and withUandL040000000000and0177777777770x1'0000'0000and0'37777777777(C++14 digit separators)0,00and0U2147483648and429496729501777777777777777777777(2^64-1) and0777777777777777777777- a binary literal of 32 ones
-037777777777
All of them got the types the standard gives them. For example,
037777777777→unsigned inton every platform.037777777777L→unsigned longon unix32/win64 andsigned longon unix64. Octal 2^64-1 →unsigned long longon unix32/win64 andunsigned longon unix64. Decimal literals still never become unsigned.
Automated review of f23df7d by Claude. The pull request was built and tested locally.
No description provided.